var AttendanceDetail = function() {
	return {
		datatable : null,
		init : function() {
			$("#startTime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m-d"});
			$("#endTime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m-d"});
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var attendanceDetailListTable = $("#attendanceDetailListTable").dataTable({
				"sAjaxSource" : ctx + "/attendanceDetail/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {page : 1,start : 0,rows : 10,params : {}};
					if($('#userIds').val()){
						postData.params.userIds = $('#userIds').val();
						console.log($('#userIds').val());					
					}
					
					if($('#startTime').val()){
						postData.params.startTime = $('#startTime').val();
					}
					
					if($('#endTime').val()){
						postData.params.entTime = $('#endTime').val();
					}
					
					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}

					$.ajax({
						"dataType" : 'json',
						"cache": false,
						"type" : "POST",
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
				{
					"data" : "index",
					"aTargets" : [ 0 ]
				},{
					"data" : "emplName",
					"aTargets" : [ 1 ],
					'bSortable': true
				},{
					"data" : "emplCode",
					"aTargets" : [ 2 ]
				},{
					"data" : "clockIp",
					"aTargets" : [ 3 ],
					'bSortable': true
				},{
					"data" : "manHoursTypeName",
					"aTargets" : [ 4 ]
				},{
					"aTargets" : [ 5 ],
					"mRender" : function(data, type, full) {
						return new Date(full.clockTime).format("yyyy-MM-dd hh:mm:ss");
					}
				},{
					"data" : "clockPlace",
					"aTargets" : [ 6 ]
				},{
					"data" : "attnTypeName",
					"aTargets" : [ 7 ]
				}]
			});
			this.datatable = attendanceDetailListTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },initListener:function(){
			/**
			 * 监听开关事件
			 */
			// 选择员工modal
        	jQuery("#selected").click(function(){
        		$("#groupUserModal").modal('show');
        	});
			// 查询
        	jQuery("#searchBtn").click(function() { 
        		AttendanceDetail.reSearch();
				return false;
			});
     	}
	}
}();